﻿using ShunFengApi.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
namespace ShunFengApi.Common
{
   internal class ShunFengUrl
    {
        private readonly static string BaseUrl = ShunFengConfig.BaseUrl;
        private readonly static string Sf_appid = ShunFengConfig.Sf_appid;
        private readonly static string Sf_appkey = ShunFengConfig.Sf_appkey;


        #region 获取顺丰请求Url + GetRequestUrl()
        /// <summary>
        /// 获取顺丰请求Url
        /// </summary>
        /// <param name="url">接口Url</param>
        /// <param name="accessToken">accessToken：只有创建和查询AccessToken票据的时候不需要传这个字段</param>
        /// <param name="refreshToken">refreshToken：只有刷新AccessToken票据的时候需要传这个字段</param>
        /// <param name="version">版本号；v1.0 / v1.1</param>
        /// <param name="type">请求接口的类型；rest：授权类API/public : 免授权API</param>
        /// <returns></returns>
        internal static string GetRequestUrl(RequestUrlEnum url, string accessToken, string refreshToken = "", string version = "v1.0", string type = "public")
        {
            string queryUrl = EnumHelper.Instance.GetDescription(typeof(RequestUrlEnum), url);
            string re = string.Format("{0}/{1}/{2}{3}", BaseUrl, type, version, queryUrl);
            if (!string.IsNullOrEmpty(accessToken))
            {
                re += "access_token/" + accessToken + "/";
                if (!string.IsNullOrEmpty(refreshToken))
                {
                    re += "refresh_token/" + refreshToken + "/";
                }
            }
            re += string.Format("sf_appid/{0}/sf_appkey/{1}", Sf_appid, Sf_appkey);
            return re;
        } 
        #endregion

    }
}
